package com.newgoldcurrency.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.newgoldcurrency.bean.ChatBean;
import com.newgoldcurrency.databinding.ItemChatLeftBinding;
import com.newgoldcurrency.databinding.ItemChatRightBinding;

import java.util.List;

public class ChatAdapter extends ArrayAdapter<ChatBean> {
    private final Activity context;
    public ChatAdapter(@NonNull Activity context, @NonNull List<ChatBean> objects) {
        super(context, 0, objects);
        this.context=context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ChatBean bean = getItem(position);
        if (bean.type.equals("right")){
            @SuppressLint("ViewHolder") @NonNull ItemChatRightBinding binding = ItemChatRightBinding.inflate(context.getLayoutInflater());
            binding.itemChatRight.setText(bean.content);
            return binding.getRoot();
        }else {
            @SuppressLint("ViewHolder") @NonNull ItemChatLeftBinding binding = ItemChatLeftBinding.inflate(context.getLayoutInflater());
            binding.itemChatLeft.setText(bean.content);
            return binding.getRoot();
        }
    }
}
